package GUI;

import java.awt.EventQueue;


import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.border.TitledBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.AbstractTableModel;

import Entity.*;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Date;

import javax.swing.JTable;
import java.awt.Panel;
import javax.swing.JCheckBox;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

class workersTable extends AbstractTableModel
{
	String[] titles={"Worker ID","Employee Number","First Name","Last Name","Role","E-mail"};
	Object[][] data;
	
	public workersTable(Worker[] w)
	{
		super();
		this.data=new Object[w.length][6];
		for(int i=0; i<w.length; i++)
		{
			this.data[i][0]=w[i].getWorkerID();
			this.data[i][1]=w[i].getWorkerNum();
			this.data[i][2]=w[i].getFirstName();
			this.data[i][3]=w[i].getLastName();
			this.data[i][4]=w[i].getR();
			this.data[i][5]=w[i].getEmail();
			
		}
	}
	@Override
	public int getColumnCount() {
		return this.titles.length;
	}

	@Override
	public int getRowCount() {
		return data.length;
	}

	@Override
	public Object getValueAt(int arg0, int arg1) {
		return data[arg0][arg1];
	}
	
	@Override
	public String getColumnName(int column) {
		// TODO Auto-generated method stub
		return (String) this.titles[column];
	}
}


/**
 * this is the GUI for viewing the workers.
 * @author Sandra Krasko
 */
public class viewWorkers extends JPanel {

	private JPanel contentPane;
	private JTable table;
	
	JFrame frame;
	JPanel lastPanel;
	public void setLastPanel (JPanel panel)
	{
		this.lastPanel=panel;
	}
	public void setFrame (JFrame frame)
	{
		this.frame=frame;
	}

	/**
	 *  is the constructor. it has a table to chose from and save after validate.
	 */
	public viewWorkers(Worker[] w) {
		final Worker[] w2=w;
		setBounds(100, 100, 918, 403);
		setLayout(null);
		setLayout(null);
		
		table = new JTable(new workersTable(w));
		table.setBounds(270, 64, 241, 124);
		JScrollPane sp=new JScrollPane(table);
		sp.setBounds(10, 11, 678, 247);
		add(sp);
		
		JButton btnCancel = new JButton("Back");
		btnCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.setContentPane((JPanel)lastPanel);
			}
		});
		btnCancel.setBounds(291, 269, 89, 23);
		add(btnCancel);
	}

}
